<template>
	<div class="invoice" v-if="data">
		<ul v-if="data.length">
			<li class="border-b" v-for="item in data" @click="setInvoice(item)">
				<van-swipe-cell :right-width="60">
					<van-cell-group class="layout-juscon pl15 pr15 pt20 pb20">
						<div class="name mr15">
							<h3 class="fs14 black mb10 ellipsis" style="width:3rem">{{ item.company_name }}</h3>
							<span class="border fs12 subject radius pl10 pr10 border-red" v-if="item.is_default == 1">默认</span>
						</div>
						<div class="flex_1">
							<h4 class="fs14 black mb10 layout"><i>{{ item.tax_no }}</i><p @click.stop="edit(item)"><img style="width:15px" src="../../../assets/icon9.png" alt=""></p></h4>
							<p class="fs12 c4a">{{ item.reg_address }}</p>
						</div>
					</van-cell-group>
					<p slot="right" class="bg-subject align-center white block full-height layout"><img class="block auto" style="width:25px" src="../../../assets/icon10.png" alt="" @click="deletes(item.id)"></p>
				</van-swipe-cell>
			</li>
		</ul>
		<template v-else>
			<default explain='暂时还没发票抬头~'></default>
		</template>		
		<router-link tag="button" to="/personal/invoice/detail" class="white bg-subject radius align-center block auto w60 pt10 pb10" style="margin-top:40%;">新增发票抬头</router-link>
	</div>
</template>

<script>
import Default from "@/components/Default";
import { SwipeCell,Dialog } from 'vant';
export default{
	components: {
		SwipeCell,
		Dialog,
		Default
	},
	data()
	{
		return{
			data   : [],
		}
	},
	created()
	{
		this.loadData();
	},
	methods:
	{
		loadData()
		{
			this.$http.get('/setting/getInvoices',{ params : { type : 0 } }).then( res => {
				this.data = res.data;
			})
		},
		deletes(id)
		{
			Dialog.confirm({
				message: '确定删除吗？'
			}).then(() => {
				this.$http.post('/setting/delinvoice',{ id : id }).then(res=>{
					this.loadData();
				})
			});
		},
		edit(item)
		{
			this.$store.dispatch('getInvoice',item);
			this.$router.push('/personal/invoice/detail?id=' + item.id + '&type=' + item.type)
		},
		setInvoice(item)
		{
			this.$http.post('/setting/setInvoice',{ id : item.id }).then( res=> {
				this.loadData();
			})
		}
	}
}
</script>

<style lang="less">
.invoice{
	.van-swipe-cell__right{
		width:60px;
	}
}
</style>